package onjava.arrays;

// arrays/ParallelSetAll.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.*;
import onjava.*;

/**
 * 
 * 数组并行。可以用<code>setAll()</code>方法初始化更大的数组。如果速度成了问题，
 * <code>Arrays.parallelSetAll()</code>（应该）能更快的完成初始化
 *
 * @author Lucky Yang
 */
public class ParallelSetAll {
  static final int SIZE = 10_000_000;

  static void intArray() {
    int[] ia = new int[SIZE];
    Arrays.setAll(ia, new Rand.Pint()::get);
    Arrays.parallelSetAll(ia, new Rand.Pint()::get);
  }

  static void longArray() {
    long[] la = new long[SIZE];
    Arrays.setAll(la, new Rand.Plong()::get);
    Arrays.parallelSetAll(la, new Rand.Plong()::get);
  }

  public static void main(String[] args) {
    intArray();
    longArray();
  }
}
